package cn.fjsay.java.demo1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;


public class JdbcDemo2 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.jdbc.Driver");

            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/persondb","root","root");
            System.out.println(conn == null ? "连接失败" : "连接成功");

            String sql = "update t_person set pname=?,pwd=?,gender=?,address=?where pid=?";
            PreparedStatement psmt = conn.prepareStatement(sql);
            psmt.setString(1,"tom");
            psmt.setString(2,"111");
            psmt.setString(3,"female");
            psmt.setString(4,"usa");
            psmt.setInt(5,5);

            int count =psmt.executeUpdate();
            System.out.println(count>0?"修改成功":"修改失败");

            psmt.close();
            conn.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

    }
}
